//
//  YFSensorApi.m
//  CoollangTennisBall
//
//  Created by Coollang on 2018/1/15.
//  Copyright © 2018年 Coollang-YF. All rights reserved.
//

#import "YFSensorApi.h"
#import "LGPeripheral+OemTypePID.h"
#import "VersionItem.h"


@implementation YFSensorApi

+ (instancetype)getLastDeviceVersionWithOemType:(OemType)oemType withComplete:(void(^)(BOOL success,YFSensorApi *resultAPi,VersionItem *item,NSError *error))completeblock{
    NSString *type = [LGPeripheral PIDwithOemType:oemType];
    YFSensorApi *lastVersionAPi = [YFSensorApi requestApiWithType:kSensorGetLastVersionAPi andParam:@{@"oemType":type}];
    [[YFNetworkingService sharedInstance] sendRequest:lastVersionAPi callback:^(BOOL success, id result, NSError *error) {
        if (success) {
             VersionItem *item = [[VersionItem alloc] initWithDictionary:lastVersionAPi.responseJSONObject[@"errDesc"]];
            if (completeblock) {
                completeblock(success,lastVersionAPi,item,nil);
            }
        }else {
            if (completeblock) {
                completeblock(success,lastVersionAPi,nil,error);
            }
        }
    }];
    return lastVersionAPi;
}

// 上传固件信息
+ (instancetype)initWithOemType:(OemType)oemType derviceMac:(NSString *)mac derviceName:(NSString *)name {
    NSString *type = [LGPeripheral PIDwithOemType:oemType];
    NSDictionary *parmaDict = @{@"oemType":[NSString checkIfNullWithString:type],
                                @"phoneType": @"IOS",
                                @"mac":[NSString checkIfNullWithString:mac],
                                @"deviceName":name,
                                };
    return [YFSensorApi requestApiWithType:kSensorBindOemTypeAndMacAPi andParam:parmaDict];
}





@end
